home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.3d26 source
/
tn3270
/
util.c
< prev
next >
Wrap
Text File
|
1991-01-21
|
6KB
|
267 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.3d21, January 17, 1991
* Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#define __SEG__ 3270seg2
#include "maclib.h"
#include "termdef.h"
#include "globals.h"
extern char smallscreen; /* complete 24 x 80 window doesn't fit */
#define IAC 255 /* Telnet protocol interpret as command: */
movmem(src, dest, len)
char *src, *dest;
short len;
{
memcpy(dest, src, len);
}
tcpmovmem(src, dest, len)
unsigned char *src, *dest;
short *len;
{
register short i, copylen;
if (tcpflg) {
if ((*len) == 0) return;
copylen = 0;
for (i=0; i < (*len); i++) {
if (src[i] == IAC) {
dest[copylen++] = IAC;
dest[copylen++] = IAC;
}
else {
dest[copylen++] = src[i];
}
}
(*len) = copylen;
}
else {
memcpy(dest, src, *len);
}
}
setmem(area, len, value)
char * area;
short len;
char value;
{
memset(area, value, len);
}
char * ctop(s)
char *s;
{
return(c2pstr(s));
}
char * ptoc(s)
char *s;
{
return(p2cstr(s));
}
GetGlobalRect(window, globalRect)
WindowPtr window;
Rect * globalRect;
{
GrafPtr gp;
GetPort(&gp);
SetPort(window);
(*globalRect) = window->portRect;
LocalToGlobal(&(globalRect->top));
LocalToGlobal(&(globalRect->bottom));
SetPort(gp);
}
defxtab(xtabinfo, xtab)
unsigned char **xtabinfo;
unsigned char *xtab;
{
Size infosize;
register short i;
/* generate default table */
for (i=0; i < 256; i++) {
xtab[i] = i;
}
/* modify specified values */
infosize = GetHandleSize((Handle)xtabinfo);
/* ensure length is a multiple of two (as it should be) */
infosize >>= 1;
infosize <<= 1;
if (infosize < 2) return;
for (i=0; i < infosize; i += 2) {
xtab[(*xtabinfo)[i]] = (*xtabinfo)[i+1];
}
}
getdeskrect(r)
Rect *r;
{
static RgnHandle *GrayRgn = (RgnHandle *)0x9ee;
(*r) = (**GrayRgn)->rgnBBox;
}
unsigned char getmodel(rows, cols)
short rows, cols;
{
/* note: for models 4 and 5, only 3278 is used, since
there are no real 3279-4 or -5 terminals */
if (colormac) {
if ((rows == 32) && (cols == 80)) return(MDL32793);
else if ((rows == 43) && (cols == 80)) return(MDL32784);
else if ((rows == 27) && (cols == 132)) return(MDL32785);
else return(MDL32792);
}
else {
if ((rows == 32) && (cols == 80)) return(MDL32783);
else if ((rows == 43) && (cols == 80)) return(MDL32784);
else if ((rows == 27) && (cols == 132)) return(MDL32785);
else return(MDL32782);
}
}
adjmove(wr) /* wr is the rectangle for a window in global coordinates */
Rect *wr; /* the position of the rectangle is adjusted to fit on
on the screen as well as possible */
{
Rect r, devrect;
Point ctr;
GDHandle devgdev;
char found;
char devok;
short adj;
r = *wr; /* local copy of window rectange */
/* get center point and corresponding device rectange */
ctr.h = (r.left + r.right)/2;
ctr.v = (r.top + r.bottom)/2;
if (colormac) {
found = 0;
devgdev = GetDeviceList();
while (devgdev != 0) {
devrect = (*devgdev)->gdRect;
if (PtInRect(&ctr, &devrect)) {
found = 1;
break;
}
else {
devgdev = GetNextDevice(devgdev);
}
}
if (!found) {
devgdev = GetMainDevice();
if (devgdev == 0) {
return; /* shouldn't happen */
}
else {
devrect = (*devgdev)->gdRect;
}
}
}
else {
devrect = qd.screenBits.bounds;
}
/* adjust for menu bar */
if ((devrect.top == 0) && (devrect.left == 0)) {
if (smallscreen) {
devrect.top = 4;
}
else {
devrect.top = 20;
}
}
/* return if window is entirely in device rectangle */
if ((devrect.top <= r.top) && (devrect.bottom >= r.bottom) &&
(devrect.left <= r.left) && (devrect.right >= r.right)) {
return;
}
if (colormac) {
/* check window will fit on device */
devok = ((devrect.bottom - devrect.top) >= (r.bottom - r.top)) &&
((devrect.right - devrect.left) >= (r.right - r.left));
/* if not, use entire desktop */
if (!devok) {
getdeskrect(&devrect);
if (devrect.top == 0) {
if (smallscreen) {
devrect.top = 4;
}
else {
devrect.top = 20;
}
}
if ((devrect.top <= r.top) && (devrect.bottom >= r.bottom) &&
(devrect.left <= r.left) && (devrect.right >= r.right)) {
return;
}
}
}
/* following order ensures that top left corner is in window */
/* make right edge fit */
adj = r.right - devrect.right;
if (adj > 0) {
r.right -= adj;
r.left -= adj;
}
/* make bottom edge fit */
adj = r.bottom - devrect.bottom;
if (adj > 0) {
r.bottom -= adj;
r.top -= adj;
}
/* make left edge fit */
adj = devrect.left - r.left;
if (adj > 0) {
r.left += adj;
r.right += adj;
}
/* make top edge fit */
adj = devrect.top - r.top;
if (adj > 0) {
r.top += adj;
r.bottom += adj;
}
(*wr) = r;
}